﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IConcentratorTypeService))]
    public class ConcentratorTypeService : CoreServiceBase, IConcentratorTypeService
    {

        [Import]
        public IConcentratorTypeRepository ConcentratorTypeRepository { get; set; }

        public IQueryable<ConcentratorType> ConcentratorTypes
        {
            get { return ConcentratorTypeRepository.Entities; }
        }

        public OperationResult Insert(Domain.ViewModels.BasicSet.ConcentratorType.ConcentratorTypeModel model)
        {
            var entity = new ConcentratorType
            {

                Ji_ZQLX = model.Ji_ZQLX,
                Ji_ZQXY = model.Ji_ZQXY,
                CreateDT = DateTime.Now,
                DefaultValue = model.DefaultValue,
               
                ReviseDT = DateTime.Now

            };
            ConcentratorTypeRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.ConcentratorType.ConcentratorTypeModel model)
        {
            var entity = new ConcentratorType
            {
                Id = model.Id,
                Ji_ZQLX = model.Ji_ZQLX,
                Ji_ZQXY = model.Ji_ZQXY,
                CreateDT = DateTime.Now,
                DefaultValue = model.DefaultValue,

                ReviseDT = DateTime.Now

            };
            ConcentratorTypeRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "修改成功");
        }

        public OperationResult Delete(int Id)
        {
            var ConcentratorTyp = ConcentratorTypes.FirstOrDefault(t => t.Id == Id);
            ConcentratorTyp.IsDeleted = true;

            ConcentratorTypeRepository.Update(ConcentratorTyp);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
